package adc.budget.impl.hb.bo;

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import adc.app.spec.IBo;

@MappedSuperclass
public abstract class HbBudgetBo implements IBo, Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    private static final ToStringStyle TO_STRING_STYLE = new ToStringStyle() {

        private static final long serialVersionUID = 1L;

        {
            setUseShortClassName(true);
            setUseIdentityHashCode(true);
        }

        /**
         * <p>
         * Ensure <code>Singleton</code> after serialization.
         * </p>
         * 
         * @return the singleton
         */
        private Object readResolve() {
            return TO_STRING_STYLE;
        }
    };

    @Override
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public boolean equals(final Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof HbBudgetBo)) {
            return false;
        }
        return equals(this.id, ((HbBudgetBo) other).id);
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(id).toHashCode();
    }

    @Override
    public String toString() {
        ToStringBuilder builder = new ToStringBuilder(this, TO_STRING_STYLE).append("id", id);
        appendPropsToString(builder);
        return builder.toString();
    }

    protected void appendPropsToString(final ToStringBuilder builder) {

    }

    protected boolean equals(final Object o1, final Object o2) {
        return o1 == o2 || o1 != null && o1.equals(o2);
    }
}
